/**
 * ToggleSplitPaneAction.java
 * @author: liuex
 * 2008-1-8 ����10:26:31
 *
 * note: 
 */
package lex.explorer;

import java.awt.event.ActionEvent;

import javax.swing.JSplitPane;

import org.lex.swing.ActionBuilder;
import org.lex.utils.IconCache;


public class ToggleSplitPaneAction extends ActionBuilder
{
	private JSplitPane split = null;
	private String selectedToolTip = null;
	private String unselectedToolTip = null;
	private int location = 0;

	public ToggleSplitPaneAction( final JSplitPane split )
	{
		this( split, "Hide Directory Tree", " Show Directory Tree" );
	}

	public ToggleSplitPaneAction( final JSplitPane split, String selectedToolTip,
			String unselectedToolTip )
	{
		this.split = split;
		this.selectedToolTip = selectedToolTip;
		this.unselectedToolTip = unselectedToolTip;
		this.setTooltip( selectedToolTip );
		this.setIcon( IconCache.getIcon( IconCache.Tree ) );
		this.location = split.getDividerLocation();
		this.setSelected( true );
	}

	@Override
	public void actionPerformed( ActionEvent e )
	{
		if( true == this.isSelected() )
		{
			split.setEnabled( true );
			split.setDividerLocation( location );
			this.setTooltip( selectedToolTip );
		}
		else
		{
			location = split.getDividerLocation();
			split.setDividerLocation( 0 );
			split.setEnabled( false );
			this.setTooltip( unselectedToolTip );
		}
	}
}
